package judesart.app.client.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import judesart.app.domain.ArtworkType;

import com.extjs.gxt.ui.client.data.ModelData;

public class ArtworkTypeModel implements ModelData
{
    private final ArtworkType type;

    private final static ArtworkTypeModel[] VALUES = new ArtworkTypeModel[ArtworkType.values().length];
    static
    {
        for (int i = 0; i < VALUES.length; i++)
        {
            VALUES[i] = new ArtworkTypeModel(ArtworkType.values()[i]);
        }
    }

    private ArtworkTypeModel(ArtworkType type)
    {
        this.type = type;

    }

    public static ArtworkTypeModel valueOf(ArtworkType type)
    {
        for (ArtworkTypeModel model : VALUES)
        {
            if (model.getType() == type)
            {
                return model;
            }
        }
        return null;
    }

    public static List<ArtworkTypeModel> values()
    {
        return Arrays.asList(VALUES);
    }

    public ArtworkType getType()
    {
        return this.type;
    }

    @Override
    public <X> X get(String property)
    {
        return (X) (type.name().toUpperCase().substring(0, 1) + type.name().toLowerCase().substring(
                1));
    }

    @Override
    public Map<String, Object> getProperties()
    {
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("value", get("value"));
        return props;
    }

    @Override
    public Collection<String> getPropertyNames()
    {
        Collection<String> names = new ArrayList<String>();
        names.add("value");
        return names;
    }

    @Override
    public <X> X remove(String property)
    {
        return null;
    }

    @Override
    public <X> X set(String property, X value)
    {
        return null;
    }

}
